<?php
//验证邮箱
function isEmail($str){
	$str = isset($str)?trim($str):'';
	$chars = "/^([a-z0-9+_]|\\-|\\.)+@(([a-z0-9_]|\\-)+\\.)+[a-z]{2,6}\$/i";
	if (strpos($str, '@') !== false && strpos($str, '.') !== false){
		if(preg_match($chars, $str)){return true;}
	}
	return false;
}



//验证数字字母
function isLetterDigital($str,$min=0,$max=0){
	$str = isset($str)?trim($str):'';
	$len = strlen($str);
	if($len<$min || ($max!==0 && $max < $len)){
		return false;
	}
	$chars = "/^[0-9a-zA-Z]+\$/i";
	if(preg_match($chars, $str)){
		return true;
	}
	return false;
}

//验证数字字母中文
function isLetterDigitalChinese($str,$min=0,$max=0){
	$str = isset($str)?trim($str):'';
	$len = strlen($str);
	if($len<$min || ($max!==0 && $max < $len)){
		return false;
	}
	$chars = "/^[0-9a-zA-Z\x{4e00}-\x{9fa5}]+\$/u";
	if(preg_match($chars, $str)){
		return true;
	}
	return false;
}
//验证数字字母下划线
function isw($str,$min=0,$max=0){
	$str = isset($str)?trim($str):'';
	$len = strlen($str);
	if($len<$min || ($max!==0 && $max < $len)){
		return false;
	}
	$chars = "/^\w+\$/i";
	if(preg_match($chars, $str)){
		return true;
	}
	return false;
}


//是否为空
function isNotEmpty($str){
	$str = isset($str)?trim($str):'';
	if($str===''){
		return false;
	}
	return true;
}

/** 价格格式  **/
function isPrice($str){
	$str = isset($str)?trim($str):'';
	$chars = "/^0$|^0\.\d{1,2}$|^[1-9]\d{0,9}$|^[1-9]\d{0,9}\.\d{1,2}?$/";
	return preg_match($chars, $str)?1:0;
}

function is_date($str){
	$date_format = 'Y-m-d';
    $str = trim($str);
    $time = strtotime($input);
    return date($date_format, $time) == $str;
}


//验证指定大小的图片
function isImg($path,$maxsize=1000000){
	if(file_exists($path)){
		$filesize=abs(filesize($path));
		if($filesize <= $maxsize){
			$type_list = array("1"=>"gif","2"=>"jpg","3"=>"png");
			$img_info = @getimagesize ($path);
			if(isset($type_list[$img_info[2]])){
				return true;
			}
		}
	}
	return false;
}


function isCharNum($str){
	$str = isset($str)?trim($str):'';
	$chars = "/^[0-9a-zA-Z]+$/";
	return preg_match($chars, $str)?1:0;
}


function isUrl($url){
	if(!filter_var($url, FILTER_VALIDATE_URL)){
		return false;
	}else{
		return true;
	}
}

